package com.example.demo.service.impl;

import com.example.demo.entity.Finance;
import com.example.demo.entity.Users;
import com.example.demo.mapper.financemapper;
import com.example.demo.service.FinanService;
import com.example.demo.util.ServiceException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class FinanceServiceImpl implements FinanService {
    @Autowired
    financemapper financemapper;
    @Override
    public void addFinance(Finance finance) {
        int add = financemapper.add(finance);
        if(add<=0){
            throw new ServiceException("添加失败");
        }
    }

    @Override
    public Users<Finance> page(int page, int size, String query) {
        List<Finance> list = financemapper.search(query);
        List<Finance> page1 = financemapper.page(page, size, query);
        Users<Finance> users=new Users<>();
        users.setUsers(page1);
        users.setTotal(list);
        users.setTotalMoney(financemapper.money());
        return users;
    }
}
